<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<input type="hidden" id="id" th:value="*{id}"/>

     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<input id="line_id" name="lineId" type="hidden">
					<input id="line_name" name="lineName" type="hidden">
					<div class="select-list">
						<ul>
							<li>
								线路名称：<input type="text" name="name"/>
							</li>

							<!--<li>
								线路类型：
								<select id="lineType" name="lineType"
										th:with="type=${@dict.getType('line_type')}">
									<option th:text="全部" value=""></option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>-->

							<li>
								电压等级：
								<select id="voltage" name="voltage"
										th:with="type=${@dict.getType('voltage_grade')}">
									<option th:text="全部" value=""></option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<!--<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>-->
							</li>
						</ul>
					</div>
				</form>
			</div>
			

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('assets:iLine:edit')}]];
        var removeFlag = [[${@permission.hasPermi('assets:iLine:remove')}]];
        var voltageGradeDatas = [[${@dict.getType('voltage_grade')}]];
        var lineType = [[${@dict.getType('line_type')}]];
        var prefix = ctx + "assets/iLine";
		var upLine = null;
		var byq = null;

        $(function() {



            $.post(ctx + "assets/b10kvLineInfo/getLineName", function (r) {
                upLine = r.b10kvLineInfo;
            });
            $.post(ctx + "assets/bByq/getByqName", function (r) {
                byq = r.bByqList;
            });

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "低压线路",
                showSearch:false,		//是否显示检索信息
                showRefresh:false,		//是否显示刷新按钮
                showToggle:false,		//是否显示详细视图和列表视图的切换按钮
                showColumns:false,		//是否显示隐藏某列下拉框
                sortable:false,		 	//是否启用排序
//		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : 'id',
					visible: false
				},
				{
					field : 'name', 
					title : '线路名称',
					sortable: true
				},
				{
					field : 'runCode', 
					title : '运行编号',
					sortable: true,
                    visible: false
				},
				{
					field : 'lineType', 
					title : '线路类型',
					sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(lineType, value);
                    },
                    visible: false
				},
				{
					field : 'voltage', 
					title : '电压等级',
					sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(voltageGradeDatas, value);
                    }
				},
				{
					field : 'totalSpan', 
					title : '线路总长度',
					sortable: true,
                    visible:false
				},
				{
					field : 'overSpan', 
					title : '架空线路总长度',
					sortable: true,
                    visible:false
				},
				{
					field : 'cableSpan', 
					title : '电缆总长度',
					sortable: true,
                    visible:false
				},
				{
					field : 'byqId', 
					title : '变压器',
					sortable: true,
                    formatter: function (value, row, index) {
                        for (index in byq) {
                            if (value == byq[index].id)
                                return byq[index].name;
                        }
                    }
				},
				{
					field : 'upLineId', 
					title : '上级线路',
					sortable: true,
                    formatter: function (value, row, index) {
                        for (index in upLine) {
                            if (value == upLine[index].id)
                                return upLine[index].name;
                        }
                    },
                    visible: false
				},
				{
					field : 'unit', 
					title : '资产单位',
					sortable: true,
					visible:false
				},
				{
					field : 'runTeam', 
					title : '运维班组',
					sortable: true,
                    visible:false
				},
				{
					field : 'addUser', 
					title : '创建人',
					sortable: true,
                    visible: false
				},
				{
					field : 'addDate', 
					title : '创建日期',
					sortable: true,
                    formatter: function (value, row, index) {
                        return value!=null?new Date(value).Format('yyyy-MM-dd'):"";
                    },
                    visible: false
				},
				{
					field : 'updateUser', 
					title : '最近更新人',
					sortable: true,
                    visible: false
				},
				{
					field : 'updateDate', 
					title : '最近更新日期',
					sortable: true,
                    formatter: function (value, row, index) {
                        return value!=null?new Date(value).Format('yyyy-MM-dd'):"";
                    },
                    visible: false
				},
				{
					field : 'datastate', 
					title : '数据状态',
					sortable: true,
                    visible: false
				},
		        {
		            title: '操作',
		            align: 'center',
					visible:false,
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);

            //单选框选择传值
            /*$("#bootstrap-table").on("check.bs.table", function (e, row, ele) {
                console.log("id和name=="+row.id+">>"+row.name)
                $("#line_id").val(row.id);
                $("#line_name").val(row.name);
            })*/


            //	对所选设备添加到数组进行传值到后台添加
            $('#bootstrap-table').on('uncheck.bs.table check.bs.table check-all.bs.table uncheck-all.bs.table',function(e,rows){
                var datas = $.isArray(rows) ? rows : [rows];        // 点击时获取选中的行或取消选中的行
                examine(e.type,datas);                              // 保存到全局 Array() 里
            });

            var overAllIds = new Array();  //ID全局数组
			var overAllNames = new Array();//Name全局数组

            function examine(type,datas){
                if(type.indexOf('uncheck')==-1){
                    $.each(datas,function(i,v){
                        // 添加时，判断一行或多行的 id 是否已经在数组里 不存则添加　
                        overAllIds.indexOf(v.id) == -1 ? overAllIds.push(v.id) : -1;
                        overAllNames.indexOf(v.name) == -1 ? overAllNames.push(v.name) : -1;
                    });
                }else{
                    $.each(datas,function(i,v){
                        overAllIds.splice(overAllIds.indexOf(v.id),1);    //删除取消选中行
                        overAllNames.splice(overAllNames.indexOf(v.name),1);    //删除取消选中行
                    });
                }
                console.log("overAllIds=="+overAllIds);
                console.log("overAllNames=="+overAllNames);
//                $("#divice_id").val(overAllIds);
                $("#line_id").val(overAllIds);
                $("#line_name").val(overAllNames);
            }


        });



        /**
         * 	日期格式化
         */
        Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }




        /**
         * 	上级线路名称
         */
//		function upLine(value,row) {
			/*$.ajax({
				 url: ctx + "assets/b10kvLineInfo/getLineName",
				 type: "post",
				 dataType: "json",
				 data: {"id":value},
				 success: function (result) {
				 	console.log("结果=="+JSON.stringify(result))
				 }
			});*/
			/*$.post(ctx + "assets/b10kvLineInfo/getLineName",function(data,status){
				console.log("lineName=="+JSON.stringify(data))
				alert("Data: " + data + "nStatus: " + status);
			});*/
//		}



	</script>
</body>
</html>